package com.booth.manage.controllers;

import com.booth.base.controllers.BaseController;
import com.booth.base.model.Users;
import com.booth.base.utils.ResultStatus;
import com.booth.manage.model.QrCode;

/***
 * 缴费二维码控制器
 * 
 * @author admin
 *
 */
public class QrCodeController extends BaseController {
	private boolean success = false;

	private final static String BASE_PAGE_URL = "qr_code";

	public void index() {
		render(BASE_PAGE_URL + "_index.jsp");
	}

	public void list() {
		renderJson(QrCode.dao.find("select * from qr_code order by code_type "));
	}
	
	public void save() {
		String aliUrl = super.upload("ali_pay");
		String txUrl = super.upload("tx_pay");
		Users u = getCurUser();
		QrCode.dao.deleteAll();
		QrCode item = new QrCode();
		item.set("code_url", aliUrl);
		item.set("code_type", 1);
		setCreator(item,u);
		success = item.save();
		item = new QrCode();
		item.set("code_url", txUrl);
		item.set("code_type", 2);
		setCreator(item,u);
		success = item.save();
		if (success)
			renderResult(ResultStatus.SUCCESS);
		else
			renderResult(ResultStatus.UPDATE_FAILURE);
	}


}
